package com.ssyx.activity.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ssyx.activity.service.CouponInfoService;
import com.ssyx.common.result.Result;
import com.ssyx.model.activity.CouponInfo;
import com.ssyx.vo.activity.CouponRuleVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * ClassName:CouponInfoController
 * Description:
 *
 * @Author kay
 * @Create 2024/5/5 21:19
 * @Version 1.0
 */
@RestController
@RequestMapping("/admin/activity/couponInfo")
//@CrossOrigin
public class CouponInfoController {

    @Autowired
    private CouponInfoService couponInfoService;

    //优惠券活动分页列表
    @GetMapping("{page}/{limit}")
    public Result index(@PathVariable Long page,
                        @PathVariable Long limit){
        Page<CouponInfo> couponParams = new Page<>(page,limit);
        IPage<CouponInfo> pageModel = couponInfoService.getPage(couponParams);
        return Result.ok(pageModel);
    }

    //新增优惠券
    @PostMapping("save")
    public Result save(@RequestBody CouponInfo couponInfo) {
        couponInfoService.save(couponInfo);
        return Result.ok(null);
    }

    //修改优惠券
    @PutMapping("update")
    public Result updateById(@RequestBody CouponInfo couponInfo) {
        couponInfoService.updateById(couponInfo);
        return Result.ok(null);
    }

    //删除优惠券
    @DeleteMapping("remove/{id}")
    public Result remove(@PathVariable Long id) {
        couponInfoService.removeById(id);
        return Result.ok(null);
    }

    //获取优惠券
    @GetMapping("get/{id}")
    public Result getCouponInfoById(@PathVariable Long id) {
        CouponInfo couponInfo = couponInfoService.getCouponInfoById(id);
        return Result.ok(couponInfo);
    }

    //获取优惠券规则信息
    @GetMapping("findCouponRuleList/{id}")
    public Result findActivityRuleList(@PathVariable Long id){
        Map<String,Object> map = couponInfoService.findCouponRuleList(id);
        return Result.ok(map);
    }

    //添加优惠券规则数据
    @PostMapping("saveCouponRule")
    public Result saveCouponRule(@RequestBody CouponRuleVo couponRuleVo){
        couponInfoService.saveCouponRule(couponRuleVo);
        return Result.ok(null);
    }


}
